import request from "@/utils/request";
import {
  Category1ListRes,
  Category2ListRes,
  Category3ListRes,
  CategoryBasicAttrItem,
  CategoryBasicAttrRes,
} from "./modules/categoryModules";

enum Api {
  getCategory1Url = "/admin/product/getCategory1",
  getCategory2Url = "/admin/product/getCategory2/",
  getCategory3Url = "/admin/product/getCategory3/",
  getCategoryBasicAttrUrl = "/admin/product/attrInfoList/",
  addOrUpdateAttrValueUrl = "/admin/product/saveAttrInfo",
  deleteOneAttrUrl = "/admin/product/deleteAttr/",
}

/**
 * 获取一级分类列表
 * @returns 一级分类列表数组
 */
export const getCategory1ListApi = () => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.get<any, Category1ListRes>(Api.getCategory1Url);
};

/**
 * 获取二级分类列表
 * @param category1Id 一级分类列表id
 * @returns 二级分类列表数组
 */
export const getCategory2ListApi = (category1Id: number) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.get<any, Category2ListRes>(
    Api.getCategory2Url + `${category1Id}`
  );
};

/**
 * 获取三级分类列表
 * @param category2Id 二级分类列表id
 * @returns 三级分类列表数组
 */
export const getCategory3ListApi = (category2Id: number) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.get<any, Category3ListRes>(
    Api.getCategory3Url + `${category2Id}`
  );
};

/**
 * 获取商品基础属性列表
 * @param category1Id 一级分类列表id
 * @param category2Id 二级分类列表id
 * @param category3Id 三级分类列表id
 * @returns 商品基础属性列表
 */
export const getCategoryBasicAttrApi = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.get<any, CategoryBasicAttrRes>(
    Api.getCategoryBasicAttrUrl + `${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 新增或修改商品属性
 * @param attrList
 * @returns null
 */
export const addOrUpdateAttrValueApi = (attrList: CategoryBasicAttrItem) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.post<any, null>(Api.addOrUpdateAttrValueUrl, attrList);
};

/**
 * 删除一条属性
 * @param attrId 需要删除的属性ID
 * @returns null
 */
export const deleteOneAttrApi = (attrId: number) => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return request.delete<any, null>(Api.deleteOneAttrUrl + `${attrId}`);
};
